// 时间过滤器
export const filters = {
	getImg(value) {
		if (value) {
			return value.indexOf('http') != -1 ? value : '"https://yong-shan-tuan.oss-cn-hangzhou.aliyuncs.com/upload/' + value;
		}
	},
    formatDate: value => {
    	if(value == undefined){
    		return;
    	}
    	//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    	value = value * 1000;
    	let date = new Date(value);
    	let y = date.getFullYear();
    	let MM = date.getMonth() + 1;
    	let DD = date.getDate();
    	return [y,MM,DD].map(item=> MM < 10 ? ('0' + MM) : MM); //年月日
    },
	splitDate(value){
		if(value == undefined){
			return;
		}
		return value.split(' ')[0]
	},
	formatYear: value => {
		if(value == undefined){
			return;
		}
		//时间戳为10位需*1000，时间戳为13位的话不需乘1000
		value = value * 1000;
		let date = new Date(value);
		let y = date.getFullYear();
		y = y.toString().substr(2,2);
		return y; //年月日
	},
	formatTime: value => {
		if(value == undefined){
			return;
		}
		//时间戳为10位需*1000，时间戳为13位的话不需乘1000,'value.length'
		console.log(value,value.toString().length,'value.length');
		value = value.toString().length == 13 ? value : (value * 1000);
		let date = new Date(value);
		let y = date.getFullYear();
		let MM = date.getMonth() + 1;
		let DD = date.getDate();
		let h = date.getHours();
		let m = date.getMinutes();
		let s = date.getSeconds();
		return [y,MM,DD].map(item=> item < 10 ? ('0' + item) : item).join('-') +' '+ [h,m,s].map(item=> item < 10 ? ('0' + item) : item).join(':'); //年月日
	},
	fenToYuan: value =>{
		let v  = (value / 100).toFixed(2);
		let arr = v.split('.');
		return arr[1] != '00' ? `${arr[0]}.${arr[1]}` : arr[0];
		
	}
}